package com.neu.chenzhiping.Dao;

import com.neu.commons.Dao.BaseDao;
import com.neu.commons.Utils.GenerateSqlDao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class dorDao {

    public int adddor(Map<String, String> map) {
        int row=0;

        GenerateSqlDao    g=new GenerateSqlDao("t_dor_info",
                "dor_id","seq_t_dor_info");
        row=g.insert(map);
        return row;
    }

    public List<Map<String,Object>> checkdor(int pageCount) {
        List<Map<String,Object>>list=new ArrayList<>();
        BaseDao b=new BaseDao();
        String sql="select  ceil(count(dor_build)/?)a from v_cy";
        list=b.BaseDaoQuery(sql,pageCount);

        return list;
    }

    public List<Map<String,Object>> findpage(int pageIndex, int pageNum) {
        List<Map<String, Object>> list=null;
        BaseDao b=new BaseDao();
        int end=pageIndex*pageNum;
        int begin=(pageIndex-1)*pageNum;

        String sql="  select * " +
                " from " +
                " (select a.*, rownum r  from" +
                " ( select * from v_cy )a where rownum<=?)b" +
                " where r>?";
       list= b.BaseDaoQuery(sql,end,begin);

     return list;
    }

    public List<Map<String,Object>> find(Map<String,String> param) {
        List<Map<String,Object>>list=null;
        GenerateSqlDao    g=new GenerateSqlDao("t_dor_info",
                "dor_id","seq_t_dor_info");
        list=g.findByEqualsParam(param);

        System.out.println(list);
        return list;

    }

    public int delete(Map<String,String> param) {
        int row=0;
        String sql="delete from t_dor_info where 1=1";
        List p=new ArrayList();
        if (param!=null){
            for ( Map.Entry<String,String>entry:param.entrySet()){
                sql+=" and "+entry.getKey()+"=? ";
                p.add(entry.getValue());
            }
        }
        System.out.println(sql+"\t"+p.toArray());
        BaseDao d=new BaseDao();
        row=d.BaseDaoUpdate(sql,p.toArray());
        System.out.println();
        return  row;

    }
}
